//
//  MessageNextViewController.m
//  LianMengZhuShou
//
//  Created by 杨腾飞 on 15/10/31.
//  Copyright © 2015年 张凯. All rights reserved.
//

#import "MessageNextViewController.h"
#import "MessageViewController.h"
@interface MessageNextViewController () <UIWebViewDelegate>

@property (nonatomic, strong) UIWebView *webView;

@property (nonatomic, strong) NSString *str;

@property (nonatomic, strong) KVNProgressConfiguration *KVN;

@end

@implementation MessageNextViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.str = self.urlStr;
    
    self.navigationItem.title = @"资讯详情";
    
    self.webView = [[UIWebView alloc] initWithFrame:self.view.bounds];
    [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.str]]];
    
    self.webView.delegate = self;
    
    // webview 自适应大小
    self.webView.scalesPageToFit = YES;
    [self.view addSubview:self.webView];
    
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"关闭" style:UIBarButtonItemStylePlain target:self action:@selector(leftBarButtonItemAction:)];
    
    
    UISwipeGestureRecognizer *swip = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipAction:)];

    [self.webView addGestureRecognizer:swip];
    
}

- (void)swipAction:(UIGestureRecognizer *)sender{
    
//    [self dismissViewControllerAnimated:YES completion:nil];
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)leftBarButtonItemAction:(UIBarButtonItem *)item{
    
//    [self dismissViewControllerAnimated:YES completion:nil];
//    [self.navigationController popViewControllerAnimated:YES];
    MessageViewController *message = [[MessageViewController alloc]init];
    [self.navigationController pushViewController:message animated:YES];
}

- (void)webViewDidStartLoad:(UIWebView *)webView
{
//    NSLog(@"开始加载");
    // 打开菊花
    self.KVN.fullScreen = YES;
    [KVNProgress showWithStatus:@"玩命加载中..."];
    
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
//    NSLog(@"结束加载");
    
    // 关闭菊花
    [KVNProgress dismiss];
    
    [self.webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByClassName('btn_2')[0].style.display = 'none'"];
    [self.webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByClassName('btn_1')[0].style.display = 'none'"];
    [self.webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByClassName('app_info')[0].style.display = 'none'"];
    [self.webView stringByEvaluatingJavaScriptFromString:@"document.getElementsByClassName('app_open')[0].style.display = 'none'"];

}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
